﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace calendar
{
public class TimeUnit
{
    private int m_value;
    private string m_name;


    private static string[] m_TU_Names = {
        "m",
        "h",
        "d",
        "w",
        "mo",
        "%",
        "y",
        "em",
        "eh",
        "ed",
        "ew",
        "emo",
        "ey",
        "e%"
    };

    private static TimeUnit Minutes = new TimeUnit(0, m_TU_Names[0]);
    private static TimeUnit Hours   = new TimeUnit(1, m_TU_Names[1]);
    private static TimeUnit Days    = new TimeUnit(2, m_TU_Names[2]);
    private static TimeUnit Weeks   = new TimeUnit(3, m_TU_Names[3]);
    private static TimeUnit Months  = new TimeUnit(4, m_TU_Names[4]);
    private static TimeUnit Percent = new TimeUnit(5, m_TU_Names[5]);
    private static TimeUnit Years   = new TimeUnit(6, m_TU_Names[6]);
    private static TimeUnit Elapsed_Minutes = new TimeUnit(7, m_TU_Names[7]);
    private static TimeUnit Elapsed_Hours   = new TimeUnit(8, m_TU_Names[8]);
    private static TimeUnit Elapsed_Days    = new TimeUnit(9, m_TU_Names[9]);
    private static TimeUnit Elapsed_Weeks   = new TimeUnit(10, m_TU_Names[10]);
    private static TimeUnit Elapsed_Months  = new TimeUnit(11, m_TU_Names[11]);
    private static TimeUnit Elapsed_Years   = new TimeUnit(12, m_TU_Names[12]);
    private static TimeUnit Elapsed_Percent = new TimeUnit(13, m_TU_Names[13]);

    private static readonly TimeUnit[] TYPE_VALUES = {
        Minutes,
        Hours,
        Days,
        Weeks,
        Months,
        Percent,
        Years,
        Elapsed_Minutes,
        Elapsed_Hours,
        Elapsed_Days,
        Elapsed_Weeks,
        Elapsed_Months,
        Elapsed_Years,
        Elapsed_Percent
    };

    public static TimeUnit MINUTES
    {
        get {
            return Minutes;
        }
    }
    public static TimeUnit HOURS
    {
        get {
            return Hours;
        }
    }
    public static TimeUnit DAYS
    {
        get {
            return Days;
        }
    }
    public static TimeUnit WEEKS
    {
        get {
            return Weeks;
        }
    }
    public static TimeUnit MONTHS
    {
        get {
            return Months;
        }
    }
    public static TimeUnit PERCENT
    {
        get {
            return Percent;
        }
    }
    public static TimeUnit YEARS
    {
        get {
            return Years;
        }
    }
    public static TimeUnit ELAPSED_MINUTES
    {
        get {
            return Elapsed_Minutes;
        }
    }
    public static TimeUnit ELAPSED_HOURS
    {
        get {
            return Elapsed_Hours;
        }
    }
    public static TimeUnit ELAPSED_DAYS
    {
        get {
            return Elapsed_Days;
        }
    }
    public static TimeUnit ELAPSED_WEEKS
    {
        get {
            return Elapsed_Weeks;
        }
    }
    public static TimeUnit ELAPSED_MONTHS
    {
        get {
            return Elapsed_Months;
        }
    }
    public static TimeUnit ELAPSED_PERCENT
    {
        get {
            return Elapsed_Percent;
        }
    }
    public static TimeUnit ELAPSED_YEARS
    {
        get {
            return Elapsed_Years;
        }
    }

    protected TimeUnit(int type, string name)
    {
        m_value = type;
        m_name = name;
    }

    public int Value
    {
        get {
            return m_value;
        }
    }

    public string Name
    {
        get {
            return m_name;
        }
    }

    public static TimeUnit getInstance(int value)
    {
        TimeUnit result = null;
        if (value >= 0 && value < TYPE_VALUES.Length) {
            result = TYPE_VALUES[value];
        }
        return result;
    }

    public override string ToString()
    {
        return this.Name;
    }
}
}
